from django import forms
from django.core.exceptions import ValidationError
import re


def cellphone_validator(value):
    if len(value) != 11:
        raise ValidationError('电话号码必须是11位数')
    if not value.isdigit():
        raise ValidationError('电话号码必须是纯数字')


class UserForm(forms.Form):
    username = forms.CharField(max_length=5, label="User", initial="kyo")
    password = forms.CharField(widget=forms.widgets.PasswordInput, label="Pass")
    #  email = forms.EmailField(label='Mail', initial="admin@example.com")
    age = forms.IntegerField(error_messages={'invalid': '无效的数字',
        'required': '必须提供年龄信息'})
    cell = forms.CharField(validators=[cellphone_validator])


class CommentForm(forms.Form):
    ...
